package com.system.xingzhi.controller;

import com.system.xingzhi.model.ReturnData;
import com.system.xingzhi.model.Role;
import com.system.xingzhi.model.RoleAndPage;
import com.system.xingzhi.model.User;
import com.system.xingzhi.service.RoleService;
import com.system.xingzhi.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController("/role")
@CrossOrigin
@Api(value = "/role",tags = {"角色"},description = "角色管理")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @PostMapping(value="/addRole")
    @ApiOperation(notes = "增加角色",value = "增加角色")
    public ReturnData addUser(@ModelAttribute Role role){
        return  roleService.insert(role);
    }

    @PostMapping(value="/deleteRole")
    @ApiOperation(notes = "删除角色",value = "删除角色")
    public ReturnData deleteUser(@ApiParam(name = "roleId",value = "角色id") @RequestParam("roleId") String roleId){
        return  roleService.deleteByPrimaryKey(roleId);
    }

    @PostMapping(value="/updateRole")
    @ApiOperation(notes = "更新角色",value = "更新角色")
    public ReturnData updateUser(@ModelAttribute Role role){
        return  roleService.updateByPrimaryKey(role);
    }

    @GetMapping(value="/queryRole")
    @ApiOperation(notes = "角色查询",value = "角色查询")
    public ReturnData queryUser(
            @ApiParam(name = "keyWord",value = "角色名") @RequestParam(value = "keyWord",required = false) String keyWord,
            @ApiParam(name = "pageNum",value = "页码") @RequestParam(value="pageNum") Integer pageNum,
            @ApiParam(name = "pageSize",value = "分页条数") @RequestParam(value="pageSize") Integer pageSize
    ){
        Map<String,String> map=new HashMap<>();
        map.put("keyWord",keyWord);
        return  roleService.selectByParameter(map,pageNum,pageSize);
    }
}
